

const fs = require('fs');
fs.readFile('./sucai/3-1-2promise.md', (err, data) => {
    // 如果失败则抛出错误
    if (err) throw err
    console.log(data.toString());
})


// 使用promose封装:
const p = new Promise(function (resolve, reject) {
    fs.readFile('./sucai/3-1-2promise.md', (err, data) => {
        // 如果失败则抛出错误
        if (err) reject(err)
        resolve(data)
    })
});
p.then(function (value) {
    console.log("使用promise\n", value.toString());
}, function (reason) {
    console.log('读取失败');
})

